package com.baofu.paycore.service.validate.impl.transfer;

import com.baofu.paycore.common.exception.ManagerErrorCode;
import com.baofu.paycore.common.utils.Constant;
import com.baofu.paycore.service.facade.model.transfer.TransferDTO;
import com.baofu.paycore.service.validate.AbstractPayValidate;
import com.system.commons.exception.BizServiceException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * 转账类校验
 *
 * <p>
 *     1、转账服务参数校验
 * </p>
 * User: LZQ Date: 2016/05/19  Version: 1.0
 */
@Slf4j
@Service
public class TransferValidate extends AbstractPayValidate<TransferDTO> {

    /**
     * 转账服务参数校验
     *
     * @param transferDTO   转账参数
     */
    public void paramsValidate(TransferDTO transferDTO){
        super.paramsValidate(transferDTO);

        //转账出入方不能同时为空
        if(null == transferDTO.getTransferInDTO() && null == transferDTO.getTransferOutDTO()){
            throw new BizServiceException(ManagerErrorCode.TRANSFER_PARAM_IS_NULL);
        }

        if (transferDTO.getAmt() < Constant.validateLong(transferDTO.getBizChargeAmt())){
            log.error("支付转账服务 转出金额:{},手续费金额:{}", transferDTO.getAmt(),
                    Constant.validateLong(transferDTO.getBizChargeAmt()));
            throw new BizServiceException(ManagerErrorCode.FEE_AMT_NOT_MORE_PAY_AMT);
        }
    }
}
